<template>
  <view>
    <!-- 每个商品小盒子 -->
    <view class="goodsList-item">
      <!-- 商品小盒子的左边 -->
      <view class="goodsList-item-left">
        <!-- 单选按钮 -->
          <radio :checked="item.goods_state" color="#C00000" v-if="showRadio" @click="radionChangeHandel"></radio>
        <!-- 商品图片 -->
        <image :src="item.goods_small_logo || defaultPic" class="goodsPic"></image>
      </view>
      <!-- 商品小盒子右边 -->
      <view class="goodsList-item-right">
        <!-- 商品名称 -->
        <view class="goodsName">{{item.goods_name}}</view>
        <view class="priceAndCount">
          <!-- 商品价格 -->
          <view class="goodsPrice">￥{{item.goods_price | tofixed}}</view>
          <!-- 数字输入框 -->
          <uni-number-box @change="changeValue" :min="1" :value="item.goods_count" v-if="showRadio"/>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name:"my-goods",
    props:{
      item:{
        type:Object,
        default:{}
      },
      showRadio:{
        type:Boolean,
        default:false
      }
    },
    data() {
      return {
          defaultPic:'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
        
      };
    },
    //过滤器
    filters:{
      tofixed(num){
        return Number(num).toFixed(2)
      }
    },
    methods:{
      // 子传父,通知父组件调用vuex的mutations方法动态修改勾选状态
      radionChangeHandel(){
        this.$emit('radioClick',{
          goods_id:this.item.goods_id,
          goods_state:!this.item.goods_state
        })
      },
      changeValue(count){
        this.$emit('countChange',{
          //count要强制转化为数字
           goods_count:+count,
           goods_id:this.item.goods_id,
        })
      }
    }
  }
</script>

<style lang="scss">
  .goodsList-item{
    display: flex;
    padding: 10px 5px;
    border-bottom: 1px solid #f0f0f0;
    .goodsList-item-left{
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-right: 5px;
      .goodsPic{
        width: 100px;
        height: 100px;
        display: block;
        
      }
    }
    .goodsList-item-right{
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      
      .goodsName{
        font-size: 13px;
      }
      .priceAndCount{
        display: flex;
        justify-content: space-between;
        .goodsPrice{
          font-size: 16px;
          color: #c00000;
        
        }
      }
      
    }
  }
</style>